﻿<?php
include_once('../../config.php');
include_once('../../lib/aupload.php');

if($_GET['thumb']){
$a_album_cg=$_POST[a_album_cg];
$types=array(
	'.JPG',
	'.jpg',
	'.jpeg',
	'.png',
	'.gif',
	'.bmp',
	'.x-png');
$maxfilesize = 2000000;
$thumbwidth	=200;
$thumbheight=150;
$foldera="../../up/pic/";
$thumb = 'thumb/';
$uptimeall=$_GET[uid].'/'.$a_album_cg.'/';
$folder=$foldera.$uptimeall; //上传文件路径

//swf上传
mb_http_input("utf-8");
mb_http_output("utf-8");
$type=filekzm($_FILES["Filedata"]["name"]);

	if ($_FILES["Filedata"]["size"] > $maxfilesize){
		echo "上传失败，请检查文件大小是否符合标准<br />文件大小:".($_FILES["Filedata"]["size"] / 1024) . " Kb";
		exit;
	}
	if ($_FILES["Filedata"]["error"] > 0){
		echo "返回错误: " . $_FILES["Filedata"]["error"] . "<br />";
	}else{
		if(!file_exists($folder)){
			mkdirm($folder);
		}
		if(!file_exists($folder.$thumb)){
			mkdirm($folder.$thumb);
		}
		$img_name = $_FILES["Filedata"]["name"];
		$img_length = $_FILES["Filedata"]["size"];
		$img_size = getimagesize($_FILES["Filedata"]["tmp_name"]);
		$savepath = $folder.$img_name;
		if (file_exists($savepath)){
			echo "文件已经存在.";exit;
		}else{
			move_uploaded_file($_FILES["Filedata"]["tmp_name"],
			$savepath);
		}
		//生成缩略图
		if($_GET['thumb']=='1'){
			$pinfo=pathinfo($savepath);
			$savethumbpath=$folder.$thumb.$pinfo["basename"];
			$r_thumb=thumb($savepath,$savethumbpath,$thumbwidth,$thumbheight);
		}
		//存储数据库
		$str_album_up="INSERT INTO `a_album_image`
		(`album_id`,`image`,`size`,`thumb`)
		VALUES('$a_album_cg','$img_name','$img_size','$r_thumb')";
		$rs_album_upimg = Afun_db()->exec($str_album_up);
		if($rs_album_upimg){
			echo "储存至: ".$savepath;
			echo "<img src='".$savethumbpath."'>";
		}
	}
}
?>
